<%-- 
    Document   : home-main
    Created on : 13-Nov-2012, 13:10:18
    Author     : Roald
--%>


<%-- Main Content: /WEB-INF/home-main.jsp --%>

<%-- 
    Document   : latest-news
    Created on : 09-Jan-2013, 14:37:45
    Author     : Roald
--%>
<%@page import="nl.hva.web.mvcwebapp.models.News"%>
<%@page import="nl.hva.web.mvcwebapp.doa.NewsDAO"%>
<%@page import="java.util.List;"%>


<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!--  **************** Multi Language ******************** -->
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<% 
session = request.getSession(true);
String lang = (String) session.getAttribute("lang");
if(lang==null){
    //default language if language not set.
    lang = "nl";
}
%>
<fmt:setLocale value="<%=lang%>" />
<fmt:setBundle basename="<%=lang%>" />
<!--  **************** Multi Language END ******************** -->

<%    
    List<News> newslist = NewsDAO.getNewsMax(1);
    request.setAttribute("latestNews", newslist);
%>
<h1> <fmt:message key="home-title"/></h1>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
    Ut id odio eu purus vulputate interdum vel id ante. 
    Vivamus egestas, metus sed aliquam volutpat, tellus nunc lacinia tortor, ut feugiat ipsum purus at mauris. </p>
<!--<a href="URL" onclick="window.open('<%=request.getContextPath()%>/chat/login', 'venster_naam', 'menubar=0,resizable=1,width=1000,height=500'); return false">Chat</a>-->
<hr />
<div class="news-item">

    <c:catch var="catchNews">
        <c:choose>
            <c:when test="${latestNews.size() != null}">

                <c:forEach var="newsItem" items="${requestScope.latestNews}">
                    <div id="date">
                        <span>${fn:substring(newsItem.newsdate,8,10)}</span>
                        <c:choose>
                            <c:when test="${fn:substring(newsItem.newsdate,5,7) == 01}"><span>JAN</span></c:when>
                            <c:when test="${fn:substring(newsItem.newsdate,5,7) == 02}"><span>FEB</span></c:when>
                            <c:when test="${fn:substring(newsItem.newsdate,5,7) == 03}"><span>MAR</span></c:when>
                            <c:when test="${fn:substring(newsItem.newsdate,5,7) == 04}"><span>APR</span></c:when>
                            <c:when test="${fn:substring(newsItem.newsdate,5,7) == 05}"><span>MAY</span></c:when>
                            <c:when test="${fn:substring(newsItem.newsdate,5,7) == 06}"><span>JUN</span></c:when>
                            <c:when test="${fn:substring(newsItem.newsdate,5,7) == 07}"><span>JUL</span></c:when>
                            <c:when test="${fn:substring(newsItem.newsdate,5,7) == 08}"><span>AUG</span></c:when>
                            <c:when test="${fn:substring(newsItem.newsdate,5,7) == 09}"><span>SEP</span></c:when>
                            <c:when test="${fn:substring(newsItem.newsdate,5,7) == 10}"><span>OCT</span></c:when>
                            <c:when test="${fn:substring(newsItem.newsdate,5,7) == 11}"><span>NOV</span></c:when>
                            <c:when test="${fn:substring(newsItem.newsdate,5,7) == 12}"><span>DEC</span></c:when>
                        </c:choose>
                        <span>${fn:substring(newsItem.newsdate,0,4)}</span>
                    </div>
                    <div class="news-content">
                        <h1>${newsItem.newstitle}</h1>
                        ${newsItem.newscontent}
                    </div>
                    <a class="right" href="news/view?newsid=${newsItem.newsid}">Continue Reading..</a>

                </c:forEach>
            </c:when>
            <c:otherwise>
                <fmt:message key="home-no-news"/>
            </c:otherwise>
        </c:choose> 

    </c:catch>
    <c:if test="${catchNews != null}">
        There was an error catching the news Feed!
        ${catchNews.message}
    </c:if>
</div>
